package com.niuniu.rushdorm.service.impl;

/**
 * @author Meng
 */
import com.niuniu.rushdorm.exception.ReportedException;
import com.niuniu.rushdorm.mapper.CredentialMapper;
import com.niuniu.rushdorm.pojo.entity.Credential;
import com.niuniu.rushdorm.service.CredentialService;
import com.niuniu.rushdorm.util.StatusEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CredentialServiceImpl implements CredentialService {
    @Resource
    CredentialMapper credentialMapper;

    @Override
    public Long verifyCredential(String username, String password) {
        Credential credential = credentialMapper.getCredential(username);
        if(credential== null){
            throw ReportedException.build(StatusEnum.LOGIN_NAME_NOT_EXIST);
        }
        if(!password.equals(credential.getPassword())){
            throw ReportedException.build(StatusEnum.LOGIN_NAME_OR_PWD_ERROR);
        }
        return credential.getUid();
    }
}
